package com.wyx.springbootspringkafkademo.producer;

import com.wyx.springbootspringkafkademo.entity.User;
import jakarta.annotation.Resource;
import org.apache.avro.generic.GenericRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

/**
 * ClassName UserProducer
 * Description TODO
 *
 * @author qq
 * @date 2025/4/25 16:12
 * @since JDK 1.8
 */
@Service
public class UserProducer {
    @Resource(name = "avroKafkaTemplate")
    private  KafkaTemplate<String, GenericRecord> avroKafkaTemplate;

    public static final  String TOPIC="user-topic";

    public void sendUser(User user) {
        avroKafkaTemplate.send(TOPIC, String.valueOf(user.getId()), user);
    }
}
